package com.sz.zhiling.controller;

import com.sz.zhiling.model.PageBean;
import com.sz.zhiling.model.TCity;
import com.sz.zhiling.service.ICitySerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/citys")
public class CityController {


    @Autowired
    private ICitySerivce iCitySerivce;


    //0.无分页查询所有城市；
    @RequestMapping("/list")
    @ResponseBody    //返回一个json;
    public PageBean<TCity>  getAllCity(Model model) {
        return iCitySerivce.getAllCity(1, 5);
    }

    //1.带分页查询所有城市；
    @RequestMapping("/getAllByPages")
    @ResponseBody    //返回一个json;
    public PageBean<TCity>  getAllByPages(Model model, int index, int size) {
        return iCitySerivce.getAllCity(index, size);
    }


    //2.查询所有的省；
    @RequestMapping("/getAllProvince")
    @ResponseBody
    public List<TCity> getAllProvinces() {
        return iCitySerivce.getAllProvinces();
    }
    //3.通过cid查城市
    @RequestMapping("/getCityByCid")
    @ResponseBody
    public TCity getCityByCid(int cId){

        return iCitySerivce.getCityByCid(cId);
    }


    @RequestMapping("/delete")
    @ResponseBody
    public PageBean<TCity> delete(int cId){
        System.out.println(cId);
        iCitySerivce.delete(cId);
       return iCitySerivce.getAllCity(1,2);



    }
}



